function pluralize(time, label) {
    if (time === 1) {
      return time + label
    }
    return time + label + 's'
  }
  
  export function timeAgo(time) {
    const between = Date.now() / 1000 - Number(time)
    if (between < 3600) {
      return pluralize(~~(between / 60), ' minute')
    } else if (between < 86400) {
      return pluralize(~~(between / 3600), ' hour')
    } else {
      return pluralize(~~(between / 86400), ' day')
    }
  }
  
  export function parseTime(time, cFormat) {
    if (arguments.length === 0) {
      return null
    }
  
    if(time == null) {
        return "";
    }
  
    if ((time + '').length === 10) {
      time = +time * 1000
    }
  
    const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
    let date
    if (typeof time === 'object') {
      date = time
    } else {
      date = new Date(parseInt(time))
    }
    const formatObj = {
      y: date.getFullYear(),
      m: date.getMonth() + 1,
      d: date.getDate(),
      h: date.getHours(),
      i: date.getMinutes(),
      s: date.getSeconds(),
      a: date.getDay()
    }
    const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
      let value = formatObj[key]
      if (key === 'a') return ['一', '二', '三', '四', '五', '六', '日'][value - 1]
      if (result.length > 0 && value < 10) {
        value = '0' + value
      }
      return value || 0
    })
    return time_str
  }
  
  export function formatTime(time, option) {
    time = +time * 1000
    const d = new Date(time)
    const now = Date.now()
  
    const diff = (now - d) / 1000
  
    if (diff < 30) {
      return '刚刚'
    } else if (diff < 3600) { // less 1 hour
      return Math.ceil(diff / 60) + '分钟前'
    } else if (diff < 3600 * 24) {
      return Math.ceil(diff / 3600) + '小时前'
    } else if (diff < 3600 * 24 * 2) {
      return '1天前'
    }
    if (option) {
      return parseTime(time, option)
    } else {
      return d.getMonth() + 1 + '月' + d.getDate() + '日' + d.getHours() + '时' + d.getMinutes() + '分'
    }
  }
  
  /* 数字 格式化*/
  export function nFormatter(num, digits) {
    const si = [
      { value: 1E18, symbol: 'E' },
      { value: 1E15, symbol: 'P' },
      { value: 1E12, symbol: 'T' },
      { value: 1E9, symbol: 'G' },
      { value: 1E6, symbol: 'M' },
      { value: 1E3, symbol: 'k' }
    ]
    for (let i = 0; i < si.length; i++) {
      if (num >= si[i].value) {
        return (num / si[i].value + 0.1).toFixed(digits).replace(/\.0+$|(\.[0-9]*[1-9])0+$/, '$1') + si[i].symbol
      }
    }
    console.log(num + "-" + digits)
    return num.toString()
  }
  
  export function html2Text(val) {
    const div = document.createElement('div')
    div.innerHTML = val
    return div.textContent || div.innerText
  }
  
  export function toThousandslsFilter(num) {
    return (+num || 0).toString().replace(/^-?\d+/g, m => m.replace(/(?=(?!\b)(\d{3})+$)/g, ','))
  }
  export function FormatMoney(num) {
      if(num==''||num==undefined||num==null){
          return 0;
      }
      var re = new RegExp('^-?\\d+(?:\.\\d{0,' + (2 || -1) + '})?');
      return num.toString().match(re)[0];
  
      // var result = ( parseInt( num * 100 ) / 100 ).toFixed(2);
      // if(result.substr(-2, 2) === "00") {
      //     result = parseInt(num);
      // }
  
      // return result;
      // var result = parseFloat(num);
      // if (isNaN(result)) {
      //     return num;
      // }
      // result = Math.round(num * 100) / 100;
      // return result;
  }
  
  export function FormatMoney2(value) {
      // if(value >= 10000) {
      //     return FormatMoney(value / 10000) + "万"
      // }
  
      return FormatMoney(value);
  
      // return value
  }
  
  
  export function thumbnail(picture) {
    //   return picture + "?x-image-process=image/resize,m_lfit,h_100,w_100"
      return picture + '?imageView2/1/w/100/h/100';
  }
  
  export function formatPercent(percent) {
      if(percent != "") {
          let a = parseFloat(percent * 100)
          if(isNaN(a)) {
              a = 0;
          }
          return FormatMoney(a) + "%";
      }
  
      return "0%";
  }
  
  
  export function formatSex(sex) {
      if(sex == "1") {
          return "男";
      } else if(sex == "0") {
          return "女";
      }
  
      return "未知";
  }
  
  export function getAreaTypeName(type) {
      switch (type) {
          case 1:
              return "区县";
          case 2:
              return "市";
          case 3:
              return "省";
          case 4:
              return "国";
          default:
              return "未知";
      }
  }
  
  export function getAgencyTypeName(type, industry) {
      if(type == 1) {
          //垂直
          if(industry) {
              try {
                  let ret = [];
                  let industryJson = JSON.parse(industry);
                  if(industryJson && industryJson.length > 0) {
                      industryJson.forEach((item)=>{
                          ret.push(item.name)
                      })
                  }
  
                  return ret.join(", ");
              } catch (e) {
  
              }
          }
  
          return "垂直";
      } else {
          return "综合";
      }
  }
  
  export function formatParentType(parentType, parentName) {
      if(parentType == "2") {
          return "平台";
      } else if(parentType == "1") {
          if(parentName) {
              return parentName;
          }
          return "商户";
      } else {
          if(parentName) {
              return parentName;
          }
          return "个人";
      }
  }
  
  
  export function formatPayTool(payTool) {
      if(payTool === 0) {
          return "微信"
      } else if(payTool === 1) {
          return "支付宝"
      } else if(payTool === 2) {
          return "微信H5"
      } else if(payTool === 3) {
          return "支付宝H5"
      } else if(payTool === 4) {
          return "微信小程序"
      } else if(payTool === 5) {
          return "支付宝小程序"
      }
      // if(payTool === 0 || payTool === 1) {
      //     return payTool === 1 ? "支付宝" : "微信"
      // }
  
      return "-----";
  }
  
  export function formatOrderStatus(status) {
      switch(status) {
          case 0:
              return "待结清";
          case 1:
              return "交易完成";
          case 2:
              return "支付失败";
          case 3:
              return "首付已完成";
          case 4:
              return "待支付尾款";
          default:
              return "";
      }
  }
  
  export function getMemberTypeName(type) {
      switch (type) {
          case 0:
              return "个人";
          case 1:
              return "商家";
          default:
              return "平台";
      }
  }
  
  export function getMemberHanBindWeixin(row) {
      return row.wxAppOpenId || row.wxMiniOpenId || row.wxPublicOpenId ? "是" : "否";
  }
  
  export function getFromOS(os) {
      switch (os) {
          case "0":
              return "android";
          case "1":
              return "ios";
          case "2":
              return "微信";
          case "3":
              return "小程序";
          default:
              return "其他";
      }
  }
  
  export function getMemberQr(memberId) {
      return process.env.VUE_APP_URI_BASE + "poster/u/" + memberId + "/qr.png";
  }
  
  export function getMemberHaibao(memberId, index) {
      return process.env.VUE_APP_URI_BASE + "poster/u/" + memberId + "/" + index + ".png";
  }
  
  export function getEmployeeDisplay(role) {
      switch (role) {
          case 1:
              return "管理员";
          default:
              return "";
      }
  }
  
  export function getPayTypeName(type) {
      switch (type) {
          case 1:
              return "押金付款";
          default:
              return "非押付款";
      }
  }
  export function getPaymentTypeName(type) {
      switch (type) {
          case 0:
              return "佣金";
          case 1:
              return "返利";
          case 2:
              return "消费";
          case 3:
              return "发出提现请求";
          case 4:
              return "提现请求被驳回";
          case 5:
              return "提现完成";
          case 6:
              return "订单收入";
          case 7:
              return "更新商户数";
          case 8:
              return "平台账户";
          case 9:
              return "推广佣金";
          default:
              return "";
      }
  }
  export function getWithdrawTypeName(type) {
      switch (type) {
          case 1:
              return "待核销";
          case 2:
              return "完成";
          case 3:
              return "驳回";
          case 0:
              return "待审核";
          default:
              return "----";
      }
  }

  export function levelDisplay(row) {
      let str = "|-";

      return str.repeat(row.level - 1) + (row.level > 0 ? ' ' : '') + row.name;
  }